<?php
	include(ROOTPATH .'include'. DS .'protect.php');
	include ROOTPATH .'include'. DS .'isMyQuery.php';
	include(ROOTPATH .'include'. DS .'checkUserLogin.php');
	$powder_min = 9 ;
	include(ROOTPATH .'include'. DS .'checkPowder.php');
	
	$page = (int)getQuery('page');
	if($page == 0)
		$page = 1;

	
	$newPhoto = new userUploadPhoto ;
	$sqlCount = 'SELECT * FROM `'.DB_PRE.'file` WHERE `thumb` is null OR `thumb` = "" ORDER BY `id` DESC';
	$sql = $sqlCount .' limit '. (($page - 1) *  50 ) .' , 50 ' ;
	$shows = $dbs -> select($sql);
	
	foreach($shows as $show){		 
		//如果是默认图 ，就把把文件的第一个图片作为封面
		$thumbs = explode('|',$show['file']);
		foreach($thumbs as $thumb){
			$fileType = getFileExt($thumb);
			if( $fileType == 'jpg' ||  $fileType == 'jpeg' ){
				$mediaThumbPhoto = moveUploadFile(array($thumb), MEDIAYHUMBPHOTO_PATH ,'copy' , UPLOADFILE_PATH );	
				break ;
			}			
		}
		
		if( '' != $mediaThumbPhoto){
			$saveName = date('His') . rand(100000,999999) ;
			$savePath = MEDIAYHUMBPHOTO_PATH . creatFolder(MEDIAYHUMBPHOTO_PATH);
			$mediaThumbPhoto = $newPhoto -> cropUserPhoto($mediaThumbPhoto, $savePath , $saveName , MEDIA_THUMB_WIDTH , MEDIA_THUMB_HEIGHT   );
			
			
			$array = array();
			$array['thumb'] = $mediaThumbPhoto ;
			$dbs -> update(  DB_PRE .'file' , $array , ' id = '. $show['id']);
			
			$update = array();
			$update['file_id'] = $show['id'] ;
			$update['user_id'] = $user -> id();			
			$update['created'] = time();

			$dbs -> insert( DB_PRE.'system_creat_thumb' ,$update );
		}
	 
		 
		
	 	
	} 
	if( count($shows) ==0 ){
		$page = -1;
	}
	header('Location:'. ROOT_PATH. '?option=admin.creatThumb&page='. $page   );
	
 
?>